#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os,subprocess
import shutil
import tkinter.messagebox


all_func = {'&清理缓存':'clearcache','&配置渲染':'set_render'}



def clearcache():
    a = os.listdir(r'C:\Users')
    for i in a:
        pat = r'C:\\Users\\' + i + r'\\AppData\\Local\\Redshift\\Cache'
        if os.path.isdir(pat):
            print(pat)
            shutil.rmtree(pat)

    if not os.path.exists(pat):
                tkinter.messagebox.showinfo('提示', '缓存清理成功')

#配置渲染
def set_render():
    if_goon = tkinter.messagebox.askokcancel('提示','配置渲染会覆盖当前账号的我的文档中的maya配置，继续吗？')
    if if_goon :
        # filepath = str(os.path.split(os.path.realpath(__file__))[0])
        filepath = r'\\Serfile\public\Reference\TD\render_setting\2017_install'
        file_2017 = filepath + r'\2017\*.* '
        print('aaa:' + file_2017)
        use = os.environ['USERNAME']
        pat = os.path.join('c:\\','Users',use,'Documents','maya','2017','*.* /s /h /y')
        # print(pat)
        os.system('@echo off')
        os.system('xcopy ' + file_2017 + pat)


        reg = os.path.join('hkey_local_machine','system','currentcontrolset','control','session manager','environment')
        regset = 'set regpath=' + reg
        # print(reg)
        os.system(regset)
        os.system('reg delete "%s" /v "PEREGRINEL_LICENSE"  /f'%reg)
        # os.system('echo "PEREGRINEL_LICENSE_remove"')

        a = 'C:/Program Files/Autodesk/Maya2017/modules/mtoa.mod'
        b = 'C:/Program Files/Autodesk/Maya2017/modules/pgYetiMaya.mod'
        c = 'C:/maya_2017_plugins'
        if os.path.exists(a):
            os.remove(a)
        if os.path.exists(b):
            os.remove(b)
        if os.path.exists(c):
            os.remove(c)


        fileplugins = filepath + r'/maya_2017_plugins/*.* '
        os.system('xcopy %s C:/maya_2017_plugins/*.* /s /h /y'%fileplugins)

        filelic = filepath + r'\maya_2017_plugins\modules\Redshift\redshift-core.lic'
        if not os.path.isdir('C:/ProgramData/Redshift'):
            os.mkdir('C:/ProgramData/Redshift')
        # print(filelic)
        shutil.copyfile(filelic,'C:/ProgramData/Redshift/redshift-core.lic')
        return True
    return False




root = tkinter.Tk()
root.withdraw()

if __name__ == '__main__':
    set_render()



































